import MySQLdb

no = int(input('部门编号: '))
name = input('部门名称: ')
location = input('部门所在地: ')

conn = MySQLdb.connect(host='47.104.31.138', port=3306,
                       database='hrs', charset='utf8',
                       user='luohao', password='Luohao.618')
try:
    with conn.cursor() as cursor:
        result = cursor.execute(
            'update tb_dept set dname=%s, dloc=%s where dno=%s',
            (name, location, no)
        )
        if result == 1:
            print('更新部门成功!!!')
    conn.commit()
except MySQLdb.MySQLError as err:
    print(err)
    conn.rollback()
finally:
    conn.close()
